# -*- coding: utf-8 -*-
"""
Module Description: 缓存通用方法
Date: 2020/09/30
Author: sxj
"""


class BaseCacheInfo(object):
    # 信息缓存基类
    def __init__(self, **kwargs):
        self.field_list = []
        for k, v in self.default_var.items():
            val = kwargs.get(k, v)
            setattr(self, k, val)
            self.field_list.append(k)

    def get_fields(self):
        return self.field_list

    def __getitem__(self, item):
        return getattr(self, item)

    def _asdict(self):
        to_dict = dict()
        for k in self.field_list:
            to_dict[k] = getattr(self, k)
        return to_dict

    def add_fields(self, field_name, val):
        setattr(self, field_name, val)
